public class Solution825 {
    public int numFriendRequests(int[] ages) {
        int[] nums=new int[121];
        int[] sum=new int[121];
        for (int age : ages) {
            nums[age]++;
        }
        sum[0]=nums[0];
        for (int i=1;i<=120;i++){
            sum[i]=sum[i-1]+nums[i];
        }
        int ans=0;
        for (int i=0;i<ages.length;i++){
            int left=ages[i]/2+7;
            int right=ages[i];
            if (left>=right){
                continue;
            }
            ans+=sum[right]-sum[left];
            if (ages[i]>left && ages[i]<=right){
                ans--;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution825().numFriendRequests(new int[]{20,30,100,110,120}));
    }
}
